package com.hf.lookatme.zview.activitys;

import android.graphics.Paint;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.hf.lookatme.R;
import com.hf.lookatme.commons.CommonMethod;
import com.orhanobut.logger.Logger;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;


/**
 * Created by JoeShiguang on 2015/5/23.
 */
public class Activity_SignUp extends Activity_Base {

  private static String TAG = "Activity_SignUp";

  @InjectView(R.id.editText_signup_userInfo_mobileNum)
  EditText editText_mobileNum;

  @InjectView(R.id.editText_signup_userInfo_validateCode)
  EditText editText_validateCode;

  @InjectView(R.id.editText_signup_userInfo_password)
  EditText editText_password;

  @InjectView(R.id.editText_signup_userInfo_confirmPassword)
  EditText editText_confirmPassword;

  @InjectView(R.id.button_signUp_getValidateCode)
  Button button_getValidateCode;

  @InjectView(R.id.textView_signUp_agreement)
  TextView textView_agreement;

  @InjectView(R.id.textView_actionBar_title)
  TextView textView_actionBar_title;

  @InjectView(R.id.imageView_actionBar_back)
  ImageView imageButton_actionBar_back;

  @InjectView(R.id.checkBox_signUp_agree)
  CheckBox checkBox_agree;

  private boolean clickable = true;

  private boolean isSelected_agreement = true;


  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);
    ButterKnife.inject(this);
    try {

      initActionBarAndControls();
    } catch (Exception ex) {
      Logger.e(TAG, "onCreate error.");
    }
  }

  private void initActionBarAndControls() {

    checkBox_agree.setSelected(true);
    imageButton_actionBar_back.setVisibility(View.VISIBLE);
    textView_actionBar_title.setText(getResources().getString(R.string.signUp));
    textView_agreement.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
  }


  @Override
  public boolean dispatchTouchEvent(MotionEvent ev) {

    if (ev.getAction() == MotionEvent.ACTION_DOWN) {

      // 获得当前得到焦点的View，一般情况下就是EditText（特殊情况就是轨迹求或者实体案件会移动焦点）
      View view = getCurrentFocus();
      if (CommonMethod.isShouldHideInput(view, ev)) {
        CommonMethod.hideSoftInput(Activity_SignUp.this, view.getWindowToken());
      }
    }
    return super.dispatchTouchEvent(ev);
  }

  @OnClick(R.id.imageView_actionBar_back)
  void onImageView_actionBar_BackClicked(View view) {

    if (!clickable) {
      return;
    }
    if (CommonMethod.isFastDoubleClick()) {
      return;
    }
    Activity_SignUp.this.finish();
  }

  @OnClick(R.id.checkBox_signUp_agree)
  void onCheckBox_agreeClicked(View view) {

    if (!clickable) {
      return;
    }
    if (CommonMethod.isFastDoubleClick()) {
      return;
    }
    if (isSelected_agreement) {

      view.setSelected(false);
    } else {

      view.setSelected(true);
    }
    isSelected_agreement = !isSelected_agreement;
  }

}
